//
//  ButtonSwitchView.m
//  YHT
//
//  Created by T-Mac on 9/26/16.
//  Copyright © 2016 yht. All rights reserved.
//

#import "ButtonSwitchView.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height



@implementation ButtonSwitchView
{
    UIButton *leftB, *rightB,*leftA,*rightA;
    UIView  *vertical;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)init
{
    self = [super init];
    if (self) {
        NSArray *titleArray = @[@"热门推荐",@"最高收益",@"当日返现",@"风控得分"];
        CGFloat btnWidth = kScreenWidth/4;
        CGFloat btnHeight = 30;
        for (int i = 0; i<4; i++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
            btn.frame = CGRectMake(btnWidth * i, 5, btnWidth, btnHeight);
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
            [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            btn.tag = 100+i;
            
             [self addSubview:btn];
        }
        leftA = [self viewWithTag:100];
        rightA = [self viewWithTag:101];
        leftB = [self viewWithTag:102];
        rightB = [self viewWithTag:103];
        
        //第一个
        [leftA setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [[leftA rac_signalForControlEvents:UIControlEventTouchUpInside
         ] subscribeNext:^(id x)
         {
             [vertical mas_remakeConstraints:^(MASConstraintMaker *make)
              {
                  make.left.right.bottom.mas_equalTo(leftA);
                   make.height.mas_equalTo(2);
              }];
             [rightA setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             [leftB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             [rightB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             
             [leftA setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
             self.status = HotStatusRecommend;
         }];
        
        //第二个
       
        [[rightA rac_signalForControlEvents:UIControlEventTouchUpInside
          ] subscribeNext:^(id x)
         {
             [vertical mas_remakeConstraints:^(MASConstraintMaker *make)
              {
                  make.left.right.bottom.mas_equalTo(rightA);
                  make.height.mas_equalTo(2);
              }];
             
             [leftA setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             [leftB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             [rightB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             
             [rightA setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
             self.status = HotStatusTopgain;
         }];

        
        //第三个
        [[leftB rac_signalForControlEvents:UIControlEventTouchUpInside
          ] subscribeNext:^(id x)
         {
             [vertical mas_remakeConstraints:^(MASConstraintMaker *make)
              {
                  make.left.right.bottom.mas_equalTo(leftB);
                  make.height.mas_equalTo(2);
              }];
            
             
             [rightA setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             [leftA setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             [rightB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             
             [leftB setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
             self.status = HotStatusDayreturn;
         }];

        //第四个
        [[rightB rac_signalForControlEvents:UIControlEventTouchUpInside
          ] subscribeNext:^(id x)
         {
             [vertical mas_remakeConstraints:^(MASConstraintMaker *make)
              {
                  make.left.right.bottom.mas_equalTo(rightB);
                  make.height.mas_equalTo(2);
              }];
            
             
             [rightA setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             [leftB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             [leftA setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
             
             [rightB setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
             self.status = HotStatusManagement;
         }];

       
        vertical = [[UIView alloc] init];
        vertical.backgroundColor = [UIColor blueColor];
        [self addSubview:vertical];
        [vertical mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(leftA);
            make.height.mas_equalTo(2);
        }];

     }
    return self;
}

@end
